package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.model.product.SpuSaleAttrValue;
import com.atguigu.gmall.model.web.AttrValueJsonVo;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.atguigu.gmall.product.service.SpuSaleAttrValueService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrValueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 钟涛
 * @description 针对表【spu_sale_attr_value(spu销售属性值)】的数据库操作Service实现
 * @createDate 2021-12-08 15:58:12
 */
@Service
public class SpuSaleAttrValueServiceImpl extends ServiceImpl<SpuSaleAttrValueMapper, SpuSaleAttrValue>
        implements SpuSaleAttrValueService {


    @Autowired
    private SpuSaleAttrMapper spuSaleAttrMapper;

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrBySkuIdAndSpuId(Long skuId, Long spuId) {
        return spuSaleAttrMapper.getSpuSaleAttrBySkuIdAndSpuId(skuId, spuId);
    }

    @Override
    public Map<String, String> getValuesSkuJson(Long spuId) {
        List<AttrValueJsonVo> valuesSkuJson = spuSaleAttrMapper.getValuesSkuJson(spuId);
        Map<String, String> data = new HashMap<>();
        for (AttrValueJsonVo attrValueJsonVo : valuesSkuJson) {
            data.put(attrValueJsonVo.getValueIds(), attrValueJsonVo.getSkuId() + "");
        }
        return data;
    }
}




